<?php

/**
 * Handles all Non Player Characters.
 *
 * @author Mark Dohmen.
 */
final class NPCManager {
	
	/**
 	 * Loads all npc's in the system.
 	 */
	final public function load() {
		$data = Database::getDatabase()->fetchArray("SELECT * FROM `npc_definitions`");
		foreach ($data as $definition) {
			if (NPCDefintion::forId($definition['id']) === NULL) {
				NPCDefintion::addDefinition(
					new NPCDefintion(
						$definition['id'], 
						$definition['name'], 
						$definition['description'], 
						$definition['health'], 
						new Inventory($definition['inventory'])
					)
				);
			}
		}
		$data = Database::getDatabase()->fetchArray("SELECT * FROM `npcs`");
		foreach ($data as $npc) {
			$newNpc = new NPC(NPCDefintion::forId($npc['id']));
			$newNpc->setLocation(new Location($npc['xpos'], $npc['ypos']));
			World::getWorld()->registerNPC($newNpc);
		}
	}
}
?>